package com.roc.web.action.ysb;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

public class YsbMonthTermActStaticsSearchCondition extends BaseSearchCondition{

	private String beginTime;
	private String agentFlag;
	private long loginid;
	protected String getOrderPartOfHQL() {
		return null;
	}

	@Override
	protected String getRowCountHQL() {
		
		StringBuffer sb = new StringBuffer();
		
		sb.append(" select count(1) from(  select d.company_name  companyid,                        \n");
		sb.append("         d.agent_account account_no,                       \n");
		sb.append("         d.agent_name    real_name,                        \n");
		sb.append("         d.term_cnt      cnt,                         \n");
		sb.append("         d.term_act_cnt  jccnt,                            \n");
		sb.append("         d.month_amt     nowmonth,                      \n");
		sb.append("         d.month_act     jhnowmonth,                    \n");
		sb.append("         substr(d.act_date,0,6)      now_month,                            \n");
		sb.append("         d.create_date   dt_create                         \n");
		sb.append("    from apsmgm.tbl_term_act_statis_day_form d           \n");
		if(Constance.isNotEmpty(agentFlag)&&"1".equals(agentFlag)){
			sb.append("        ,  (select o.id                                      \n");
			sb.append("            from apsmgm.t_operators o                      \n");
			sb.append("           where o.supri_id =").append(loginid).append("    \n ");
			sb.append("             and o.role_type in ('02', '03')) c            \n");
			sb.append("   where c.id = d.agent_id                                 \n");
		}else{
			sb.append("   where d.agent_id = ").append(loginid).append("           \n ");
		}
		sb.append("     and d.act_date = to_char(trunc(LAST_DAY(to_date('").append(beginTime).append("','yyyyMM')), 'dd'), 'yyyyMMdd') ) ");

	    return sb.toString();

	}


	protected String getSearchHQL() {

		StringBuffer sb = new StringBuffer();
		sb.append("  select d.company_name  companyid,                        \n");
		sb.append("         d.agent_account account_no,                       \n");
		sb.append("         d.agent_name    real_name,                        \n");
		sb.append("         d.term_cnt      cnt,                         \n");
		sb.append("         d.term_act_cnt  jccnt,                            \n");
		sb.append("         d.month_amt     nowmonth,                      \n");
		sb.append("         d.month_act     jhnowmonth,                    \n");
		sb.append("         substr(d.act_date,0,6)      now_month,                            \n");
		sb.append("         d.create_date   dt_create                         \n");
		sb.append("    from apsmgm.tbl_term_act_statis_day_form d           \n");
		if(Constance.isNotEmpty(agentFlag)&&"1".equals(agentFlag)){
			sb.append("        ,  (select o.id                                      \n");
			sb.append("            from apsmgm.t_operators o                      \n");
			sb.append("           where o.supri_id =").append(loginid).append("    \n ");
			sb.append("             and o.role_type in ('02', '03')) c            \n");
			sb.append("   where c.id = d.agent_id                                 \n");
		}else{
			sb.append("   where d.agent_id = ").append(loginid).append("           \n ");
		}
		sb.append("     and d.act_date = to_char(trunc(LAST_DAY(to_date('").append(beginTime).append("','yyyyMM')), 'dd'), 'yyyyMMdd') ");

		return sb.toString();
	}
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();

		return filedBeanList;
	}


	public String getBeginTime() {
		return beginTime;
	}


	public void setBeginTime(String beginTime) {
		this.beginTime = beginTime;
	}


	public String getAgentFlag() {
		return agentFlag;
	}



	public void setAgentFlag(String agentFlag) {
		this.agentFlag = agentFlag;
	}



	public long getLoginid() {
		return loginid;
	}



	public void setLoginid(long loginid) {
		this.loginid = loginid;
	}






}
